package data_manipulate;

import java.io.*;
import java.nio.file.Path;
import java.util.Random;

public class RNG {

    private BufferedWriter bw;
    private String fileName;
    private Random rand;

    public RNG(String fileName) {
        String base = System.getProperty("user.dir");
        this.fileName = base + "/tmp/" + fileName;
        this.rand = new Random(42);
    }

    public String getFileName() {
        return fileName;
    }

    public void generate(int length) {
        for (int i = 0; i < 10; i++) {
            String name = this.fileName + "" + i + ".txt";
            File file = new File(name);
            try {
                bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
                for (int j = 0; j < length; j++) {
                    int num = rand.nextInt(10000);
                    bw.write(num + "");
                    bw.newLine();
                    bw.flush();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println(i + ": complete!");
        }
    }

    public static void main(String[] args) {
        RNG rng = new RNG("rng");
        System.out.println(rng.getFileName());
        rng.generate(1000000);
    }

}
